﻿// ==========================================================
// File: Universal.WebAPI.Core.ITextSerializer.cs
// Created: 14.12.2014
// Created By: Tim cadenbach
// 
// Copyright (C) 2014 Tim Cadenbach
// License: Apache License 2.0
// ==========================================================
using System;
using System.IO;
using Universal.WebAPI.Generic;

namespace Universal.WebAPI.Interfaces
{
  /// <summary>
  /// The TextSerializer interface.
  /// </summary>
  public interface ITextSerializer                                      
  {
    /// <summary>
    /// Gets the text format
    /// </summary>
    RequestFormat Format { get; }

    /// <summary>
    /// Serializes object to a string
    /// </summary>
    /// <param name="obj">Object to serialize</param>
    /// <returns>Serialized string of the object</returns>
    string Serialize<T>(T obj);

    /// <summary>
    /// Serializes object to a stream
    /// </summary>
    /// <param name="obj">Object to serialize</param>
    /// <param name="stream">Stream to serialize to</param>
    void Serialize<T>(T obj, Stream stream);

    /// <summary>
    /// Deserializes string into an object
    /// </summary>
    /// <typeparam name="T">Type of object to serialize to</typeparam>
    /// <param name="data">Serialized object</param>
    /// <returns>Object of type T</returns>
    T Deserialize<T>(string data);

    /// <summary>
    /// Deserializes stream into an object
    /// </summary>
    /// <typeparam name="T">Type of object to serialize to</typeparam>
    /// <param name="stream">Stream to deserialize from</param>
    /// <returns>Object of type T</returns>
    T Deserialize<T>(Stream stream) where T : class;

    object Deserialize(string data, Type type);
  }
}
